home *** CD-ROM | disk | FTP | other *** search
- Path: news.uni-jena.de!news
- From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
- Newsgroups: comp.lang.c++
- Subject: Re: External access to private class variables
- Date: 2 Feb 1996 11:51:11 GMT
- Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena
- Message-ID: <4estrf$80l@fsuj01.rz.uni-jena.de>
- References: <4ermr9$ii7@cloner2.ix.netcom.com>
- Reply-To: mkt@isun04.inf.uni-jena.de
- NNTP-Posting-Host: isun07.inf.uni-jena.de
-
- > class X
- > {
- > private:
- > int value;
- > public:
- > X (int n = 0) { value = n; }
- > int& GSValue () { return value; } // return a reference to the
- > // private member "value"
- > };
-
- Of course you can return a handle to a private member.
- The member function is authorized to do so! It can access the
- private member and so can do anything it wants to do with it
- (inclusive building handles to the data and post the handles anywhere).
-
- This is a known problem! The books always say: "Never pass
- a handle to private data/functions to the outside" (or something
- like this).
-
-